package com.example.androidkt.fifth

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableField
import com.example.androidkt.R
import com.example.androidkt.R.layout.activity_data_binding
import com.example.androidkt.databinding.ActivityDataBindingBinding
import com.example.androidkt.databinding.ActivityViewModelBinding

class DataBindingActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        val binding =
            DataBindingUtil.setContentView<ActivityDataBindingBinding>(this, activity_data_binding)


        binding.apply {
            name = null
            address = "杭州"
            observeName = ObservableField("哇哈哈")
            user = User()
//            observeUserField = ObserveFieldUser()
        }

        binding.btnChange.setOnClickListener {
            binding.name = "hhm"
            binding.address = "山西"

            binding.user?.name = "韩XX"
            binding.user?.desc = "健康 幸福"


//            binding.observeUserField.name
//            binding.observeUserField.desc?.set("健康 幸福")
        }
        binding.adapter = DataBindingAdapater()
    }
}